class_name HoldAttackSpell
extends BaseHoldItem


@onready var fire_bullet_born_point: Marker2D = $FireBulletBornPoint
@onready var raise_fire_point: Marker2D = $RaiseFirePoint
@onready var hold_fire_point: Marker2D = $HoldFirePoint
@onready var particle_fire_bullet: GPUParticles2D = $ParticleFireBullet
@export var bullet_resource_name: String = "fire_bullet"
@onready var burning_audio: AudioStreamPlayer2D = $BurningAudio


func _ready() -> void:
	if burning_audio:
		burning_audio.play()
	

func _exit_tree() -> void:
	#burning_audio.stop()
	pass


func use():
	var player = holder as Player
	var config = item_data.item_config as ItemAttackSpellConfig
	
	player.raise_hand()
	particle_fire_bullet.position = raise_fire_point.position
	await get_tree().create_timer(0.3).timeout
	player.hold_hand()
	particle_fire_bullet.position = hold_fire_point.position
	
	var inst = (ResourceManager.get_resource(bullet_resource_name) as PackedScene).instantiate()
	player.level.bullets_parent.add_child(inst)
	inst.global_position = fire_bullet_born_point.global_position
	inst.attack = config.attack + player.player_data.get_attack()
	inst.critical_rate = config.critical_rate
	inst.critical_bonus = config.critical_bonus
	inst.knockback = config.knockback
	if config.attack_cam_shake:
		inst.hit_cam_shake_strength = config.attack_cam_shake_intensity
		inst.hit_cam_shake_duration = config.attack_cam_shake_duration
	inst.sender = player
	inst.dir = Vector2.RIGHT * player.view_root.scale.x
	inst.set_is_enemy(false)
	
	
	
